#pragma once
#include <memory>
#include <functional>
#include <utility>

namespace Media{
    class AVFrame{
    public:
        using Ptr = std::shared_ptr<AVFrame>;
        using ReleaseFrameFunc = std::function<void (void *frame)>;
        explicit AVFrame(void *frame = nullptr, bool isVideo = false, ReleaseFrameFunc relFrameFunc = nullptr){
            m_frame = frame;
            m_relFrameFunc = std::move(relFrameFunc);
            m_isVideo = isVideo;
        }
        ~AVFrame(){
            if(m_relFrameFunc && m_frame){
                m_relFrameFunc(m_frame);
            }
        }

        void ReleaseFrame(){
            if(m_relFrameFunc && m_frame){
                m_relFrameFunc(m_frame);
                m_frame = nullptr;
            }
        }

        bool IsVideo() const{
            return m_isVideo;
        }

        void* GetData(){
            return m_frame;
        }
    private:
        void *m_frame;
        bool m_isVideo;
        ReleaseFrameFunc m_relFrameFunc;
    };

}